﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


using Tesla.Math;

namespace Tesla.Graphics.Implementation {
    /// <summary>
    /// Abstract class for concrete subclasses to provide the underlying implementation of <see cref="TextureCube"/> and <see cref="RenderTargetCube"/>.
    /// </summary>
    public abstract class TextureCubeImplementation : GraphicsResourceImplementation {
        private SurfaceFormat _format;
        private int _size;
        private int _multiSampleCount;
        private DepthFormat _depthFormat;
        private RenderTargetUsage _usage;

        /// <summary>
        /// Gets the format of the texture resource.
        /// </summary>
        public SurfaceFormat Format {
            get {
                return _format;
            }
        }

        /// <summary>
        /// Gets the number of mip map levels in the texture resource.
        /// </summary>
        public abstract int MipCount {
            get;
        }

        /// <summary>
        /// Gets the width/height of each cube face.
        /// </summary>
        public int Size {
            get {
                return _size;
            }
        }


        /// <summary>
        /// Gets the format of the depth-stencil buffer. Only valid
        /// if the implementation represents a render target.
        /// </summary>
        public DepthFormat DepthFormat {
            get {
                return _depthFormat;
            }
        }

        /// <summary>
        /// Gets the multisample count used during multisampling. Only
        /// valid if the implementation represents a render target.
        /// </summary>
        public int MultiSampleCount {
            get {
                return _multiSampleCount;
            }
        }

        /// <summary>
        /// Gets the render target usage. Only valid if the implementation
        /// represents a render target.
        /// </summary>
        public RenderTargetUsage TargetUsage {
            get {
                return _usage;
            }
        }

        /// <summary>
        /// Creates a new instance of <see cref="TextureCubeImplementation"/>.
        /// </summary>
        /// <param name="size">The size of each cube map face.</param>
        /// <param name="format">The surface format of the texture.</param>
        public TextureCubeImplementation(int size, SurfaceFormat format) {
            _size = size;
            _format = format;
            _depthFormat = DepthFormat.None;
            _multiSampleCount = 0;
            _usage = RenderTargetUsage.DiscardContents;
        }

        /// <summary>
        /// Creates a new instance of <see cref="TextureCubeImplementation"/>, for use as a RenderTarget.
        /// </summary>
        /// <param name="size">The size of each cube map face.</param>
        /// <param name="format">The surface format of the texture.</param>
        /// <param name="depthFormat">The depth-stencil format.</param>
        /// <param name="multiSampleCount">The multisample count.</param>
        /// <param name="usage">The target usage.</param>
        public TextureCubeImplementation(int size, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage) {
            _size = size;
            _format = format;
            _depthFormat = depthFormat;
            _multiSampleCount = multiSampleCount;
            _usage = usage;
        }

        /// <summary>
        /// Gets the data from the texture.
        /// </summary>
        /// <typeparam name="T">Type of data in the array.</typeparam>
        /// <param name="face">Cube map face to read from.</param>
        /// <param name="data">Array of data.</param>
        /// <param name="mipLevel">Mip map level to access.</param>
        /// <param name="subimage">Rectangle representing a sub-image of the 2D texture to read from, if null the whole image is read from.</param>
        /// <param name="startIndex">Starting index in the array to start writing to.</param>
        /// <param name="elementCount">Number of elements to read.</param>
        public abstract void GetData<T>(CubeMapFace face, T[] data, int mipLevel, Rectangle? subimage, int startIndex, int elementCount) where T : struct;

        /// <summary>
        /// Sets the data to the texture.
        /// </summary>
        /// <typeparam name="T">Type of data in the array.</typeparam>
        /// <param name="face">Cube map face to write to.</param>
        /// <param name="data">Array of data.</param>
        /// <param name="mipLevel">Mip map level to access.</param>
        /// <param name="subimage">Rectangle representing a sub-image of the 2D texture to write to, if null the whole image is written to.</param>
        /// <param name="startIndex">Starting index in the array to start reading from.</param>
        /// <param name="elementCount">Number of elements to write.</param>
        public abstract void SetData<T>(CubeMapFace face, T[] data, int mipLevel, Rectangle? subimage, int startIndex, int elementCount) where T : struct;
    }
}
